package sg.edu.nus.iss.vmcs.service;

import sg.edu.nus.iss.vmcs.maintenance.CoinDisplay;
import sg.edu.nus.iss.vmcs.maintenance.DrinkDisplay;
import sg.edu.nus.iss.vmcs.maintenance.MaintenancePanel;
import sg.edu.nus.iss.vmcs.util.VMCSException;

public class MaintenanceDisplayService implements IMaintenanceDisplayService {

	private MaintenancePanel maintainancePanel;
	private static MaintenanceDisplayService instance;
	

	/**
	 * Return new maintainance Panel display service
	 * @return
	 */
	public static MaintenanceDisplayService getInstance(){
		
		if(instance==null){
			instance = new MaintenanceDisplayService();
		}
	
		return instance;
	}
	/**
	 * Set the maintenance panel for processing
	 * @param maintenancePanel
	 */
	public void setMaintenancePanel(MaintenancePanel maintenancePanel) {
		this.maintainancePanel = maintenancePanel;
	}
	/**
	 * Check if the maintainance panel is terminated
	 * @return
	 */
	public boolean isMaintainancePanelTerminated(){
		return (maintainancePanel==null);
	}
	/**
	 * Display the maintenancePanel
	 */
	public void displayMaintainancePanel(){
		maintainancePanel.display();
	}
	/**
	 * Set the status of the maintainance pane
	 * @param comp
	 * @param st
	 */
	public void setButtonActive(int comp, boolean st){
		maintainancePanel.setActive(comp, st);
	}
	/**
	 * Close down the maintainance panel
	 */
	public void closeDownMaintainancePanel(){
		if (maintainancePanel != null)
			maintainancePanel.closeDown();
	}
	/**
	 * Set the password state
	 * @param state
	 */
	public void displayPasswordState(boolean state){
		maintainancePanel.displayPasswordState(state);
	}
	/**
	 * Clear the password
	 */
	public void clearPassword(){
		maintainancePanel.clearPassword();
	}
	/**
	 * Set the coin quantity
	 * @param idx
	 * @param qty
	 * @throws VMCSException
	 */
	public void displayCoinQty(int idx, int qty) throws VMCSException {
		maintainancePanel.getCoinDisplay().displayQty(idx, qty);
	}
	/**
	 * display the drink quantity
	 * @param idx
	 * @param qty
	 * @throws VMCSException
	 */
	public void displayDrinkQty(int idx, int qty) throws VMCSException {
		maintainancePanel.getDrinksDisplay().displayQty(idx, qty);
	}
	/**
	 * Display price
	 * @param price
	 */
	public void displayPrice(int price){
		maintainancePanel.displayPrice(price);
	}
	/**
	 * Get the maintenance panel
	 * @return
	 */
	public MaintenancePanel getMaintainancePanel() {
		return maintainancePanel;
	}
	/**
	 * Retreived the drink display
	 * @return
	 */
	public DrinkDisplay getDrinksDisplay(){
		if(maintainancePanel!=null){
			return maintainancePanel.getDrinksDisplay();
		}
		return null;
	}
	/**
	 * Retrieve the coin display
	 * @return
	 */
	public CoinDisplay getCoinDisplay(){
		if(maintainancePanel!=null){
			return maintainancePanel.getCoinDisplay();
		}
		return null;
	
	}
	public void changeStoreQty(char type, int idx, int qty) throws VMCSException {
		maintainancePanel.updateQtyDisplay(type, idx, qty);
		maintainancePanel.initCollectCash();
		maintainancePanel.initTotalCash();
	}
	/**
	 * Set the price of the maintainance panel
	 * @param pr
	 */
	public void setPrice(String pr){
		maintainancePanel.getDrinksDisplay()
		.getPriceDisplay().setValue(pr + "C");
	}
	/**
	 * Get the current index
	 * @return
	 */
	public int getCurIdx(){
		return maintainancePanel.getCurIdx();
	}
	/**
	 * Display the number of coins
	 * @param cc
	 */
	public void displayCoins(int cc){
		maintainancePanel.displayCoins(cc);
	}
	/**
	 * Disply the total cash.
	 * @param totalCash
	 */
	public void displayTotalCash(int totalCash){
		maintainancePanel.displayTotalCash(totalCash);
	}
	/**
	 * Update the current quantity display
	 * @param idx
	 * @param qty
	 * @throws VMCSException
	 */
	public void updateCurrentQtyDisplay(int idx, int qty) throws VMCSException{
		maintainancePanel.updateCurrentQtyDisplay(idx, qty);
	}
}
